﻿//----------------------------------------------------------------
// Desc: 
// Edit: ShowLong, http://blog.csdn.net/showlong
//
// Date Created: 2009-10-15
//
// Update Date :            
//
// Copyright (c) Fuel4D (http://www.fuel4d.com), All rights reserved.
//
//----------------------------------------------------------------
#pragma once


class FAPI FUI_ScrollBar : public FUI_Object
{
    FUI_DECLARE_CLASS(FUI_ScrollBar)

    friend class FUI_List;
    friend class FUI_Report;
    friend class FUI_RichEdit;
    friend class FUI_Tree;
    friend class FUI_Rollup;
    friend class FUI_ArrayGridEx;

public:
    FUI_ScrollBar(EF_UI_WIDGET_TYPE t = eUWT_ScrollBar);
    virtual void Render(EF_UI_RENDER_LAYER layer);
    virtual void UpdateRect();
    virtual bool PtInObject(funit nX, funit nY);
    virtual bool IsChild(FUI_Object* pChild);
    virtual funit GetWidth();
    virtual bool OnMouseMove(funit nX, funit nY);
    virtual bool OnMouseWheel(bool bUp, funit nX, funit nY);
    virtual bool OnLButtonDown(funit nX, funit nY);
    virtual bool OnLButtonUp(funit nX, funit nY);
    virtual void OnFrameHide(bool visable){ bIsDown = false; }

    // 设置当前值
    void SetValue(int n);
    // 设置最大值
    void SetMax(int n);
    // 获取值
    FINLINE int GetMax(){ return nMax; }
    FINLINE int GetValue(){ return nValue; }
    // 设置单步长度
    FINLINE int GetStep(){ return nStep; }
    FINLINE void SetStep(int n){ nStep = n; }
    // 获取尺寸相关数据
    int GetWidgetHeight();
    virtual int GetUpHeight();
    virtual int GetBarHeight();
    virtual int GetDownHeight();
    // 触发一次鼠标滚轮事件
    void MouseWheel(bool bUp);
    // 
    void UpdateBar();
    // 获取部分控件数据
    FINLINE FUI_Button& GetUpB(){ return uUp; }
    FINLINE FUI_Button& GetBarB(){ return uBar; }
    FINLINE FUI_Button& GetDownB(){ return uDown; }
    //
    FINLINE bool IsFullScroll(){ return pScrollData->IsFullScroll(); }
    bool IsFullScrollWorking(funit nY){ return (((int)nY - nDownYPos) != 0);}

protected:
    virtual void InitUIData(FUI_Object* father, fuWidgetBase* pData, FUI_Layout* layout);
    virtual void Update();

protected:
    fuWidgetScrollBar* pScrollData;  // 控件数据地址
    FUI_Button uUp, uBar, uDown;
    int nStep;              // 自动滑动单步
    int nMax;               // 最大值
    int nValue;             // 当前值
    int nWidgetHeight;      // 总的滑块长度
    bool bIsDown;           // 鼠标左键是否按下
    DWORD dwDownTime;       // 按下时候的时间
    int nAutoDownVL;        // 按下时的运动方向
    int nDownYPos;          // 按下时的Y编移
    int nDownValue;         // 按下时的值
};